import request from '@/utils/request'

// 查询列表
export function fetchProductList(params) {
  return request({
    url: '/admin/products',
    method: 'get',
    params
  })
}

// 查询单条
export function fetchProduct(id) {
  return request({
    url: `/admin/products/${id}`,
    method: 'get'
  })
}

// 创建
export function createProduct(data) {
  return request({
    url: '/admin/products',
    method: 'post',
    data
  })
}

// 修改
export function updateProduct(id, data) {
  return request({
    url: `/admin/products/${id}`,
    method: 'put',
    data
  })
}

// 删除
export function deleteProduct(id) {
  return request({
    url: `/admin/products/${id}`,
    method: 'delete'
  })
}

// 批量删除
export function deleteMultipleProduct(data) {
  return request({
    url: `/admin/products/delete_checked`,
    method: 'post',
    data
  })
}

// 删除相册
export function deleteProductGallery(id) {
  return request({
    url: `/admin/products/delGallery/${id}`,
    method: 'delete'
  })
}

// 改变属性
export function changeProductAttr(id, data) {
  return request({
    url: `/admin/products/${id}/change_attr`,
    method: 'patch',
    data
  })
}
